<?php
class BaseAction extends Action {
	  
	  protected $option;
		function _initialize() {
			//参数转义
      new_addslashes($_POST);
      new_addslashes($_GET);
      $_POST = $this->__filterLabel( $_POST );
      $this->option = $this->__getOption();
      $this->assign("option",$this->option);
      $this->assign("adarray",$this->__getAds());  
			$this->assign("part",D('Cat','admin')->getAllCats()); //获得所有栏目
      //parent::_initialize();
      if(!empty($_GET['partId'])){
      	$pcat = D('Cat','admin')->getCatPcat($_GET['partId']);
				$parts = '';
				foreach($pcat as $po){
					$parts .= ' > <a href="__APP__/'.str_replace(':','/',$po['listhtml']).'/partId/'.$po['id'].'">'.$po['cname'].'</a>';
				}
				$this->assign('parts',$parts);
      }
      $this->assign("wzlinks",M('Link')->where('type=0')->order('sort asc')->select());
	  }
	  
	  private function __filterLabel( $data ){
        foreach( $data as &$value ){
            if( is_array($value) ){
                foreach( $value as &$v ){
                    $v = t( $v );
                }
            }else{
                $value = t( $value );
            }
        }
        return $data;

    }
    
    private function __getOption(){
    	if(!S("site_option")){
    	 $ops = M("Option")->findAll();
    	 foreach($ops as $op){
    	 	 $temp[$op['name']] = $op['value'];
    	 }
    	 S("site_option",$temp);
    	}
    	
    	return S("site_option");
    }
    
    private function __getAds(){
    	if(!S("site_ads")){
    	 $ops = M("Ad")->findAll();
    	 foreach($ops as $op){
    	 	 $temp[$op['code']]['url'] = $op['url'];
    	 	 $temp[$op['code']]['content'] = $op['content'];
    	 }
    	 S("site_ads",$temp);
    	}
    	
    	return S("site_ads");
    }
    
}
?>